package com.cheng.algorithm.search;

import java.util.List;

/**
 * @User Administrator
 * @Classname SeqSearch
 * @Project Data-structure-and-algorithm
 * @Description 顺序查找
 *
 * @Author wpcheng
 * @Create 2021-08-11-9:07
 * @Version 1.0
 */
public class SeqSearch {
    public static void main(String[] args) {
        int[] arr = {2, 3, 5, 12, 45, 23};

        int index = seqSearch(arr, 6);
        if (index == -1){
            System.out.println("没有找到");
        }else {
            System.out.println("已找到下标为"+index+"的元素");
        }
    }
    public static int seqSearch(int[] arr,int val){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == val){
                return i;
            }
        }
        return -1;
    }
}
